'''
@project:tinyshop_t174
@auther:zhongyingjie
@file:tyspqd_gw.py
@date:2022/11/8 15:06
@desc:
'''
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
import unittest
from common.broswersetting import broswersetting
# tinyshop 购物流程 自动化实现： 打开首页--登陆---搜索商品--选择任意一商品---进入商品详细页面---加入购物车--确定订单---支付成功(断言：如果没有成功截图)
class qdgw(broswersetting):
    def test_gw1(self):
        # driver=webdriver.Chrome()
        # driver.get('http://192.168.186.111/tinyshop/')
        # driver.maximize_window()
        # time.sleep(2)
        # driver.find_element(By.XPATH,'//a[text()="登录"]').click()
        # self.driver.find_element(By.ID,'account').send_keys('502822488@qq.com')
        # self.driver.find_element(By.NAME,'password').send_keys('cn19961011')
        # self.driver.find_element(By.XPATH,'//button[text()="登录"]').click()
        self.zzdl('502822488@qq.com','cn19961011')

        # self.driver.find_element(By.ID,'search-keyword').send_keys('男士')
        # self.driver.find_element(By.XPATH,'//button[text()="搜索"]').click()
        self.qdss('男士','加入购物车')
        # self.driver.find_element(By.XPATH,'//*[@id="main"]/div[2]/div/div/div[2]/dl/dd/ul/li[1]/dl/dt/a/img').click()
        # self.driver.find_element(By.XPATH,'//*[@id="product-intro"]/div[3]/div/dl[1]/dd/ul/li[1]/span').click()
        # self.driver.find_element(By.XPATH,'//*[@id="product-intro"]/div[3]/div/dl[2]/dd/ul/li[1]/span').click()
        # self.driver.find_element(By.XPATH, '//span[text()="加入购物车"]').click()
        # time.sleep(3)
        # gwc=self.driver.find_element(By.ID,'shopping-cart')
        # mo=ActionChains(self.driver)
        # mo.move_to_element(gwc).perform()
        # self.driver.find_element(By.XPATH,'//a[text()="去购物车结算"]').click()
        # self.driver.find_element(By.XPATH,'//a[text()="立即结算"]').click()
        # self.driver.find_element(By.XPATH,'//*[@id="main"]/div[2]/div/form/div[6]/p/input').click()
        # self.driver.find_element(By.XPATH,'//*[@id="main"]/div[2]/form/div[3]/p/input').click()
        # time.sleep(3)
        # ifzf=self.driver.window_handles
        # self.driver.switch_to.window(ifzf[1])
        try:
            '支付成功' in self.driver.page_source
        except Exception as e:
             self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\s.png')

    def test_gw2(self):
        self.zzdl('22@qq.com','123456')
        self.qdss('男士','加入购物车')

        try:
            '余额不足,请选择其它支付方式！' in self.driver.page_source
        except Exception as e:
            self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\s1.png')
    def test_gw3(self):
        self.zzdl('502822488@qq.com','cn19961011')
        self.qdss('男士','立即购买')
        try:
            '支付成功' in self.driver.page_source
        except Exception as e:
             self.driver.get_screenshot_as_file('F:\\csxm\\tinyshop_t174\\images\\s2.png')
if __name__=='__main__':
    unittest.main()
